package com.caipos.actor.ruleChain;

import com.caipos.actor.ActorSystemContext;
import com.caipos.actor.common.data.id.EntityId;
import com.caipos.actor.common.data.id.RuleChainId;
import com.caipos.actor.common.data.id.RuleNodeId;
import com.caipos.actor.common.data.id.TenantId;
import com.caipos.actor.common.data.msg.KbMsgType;
import com.caipos.actor.common.data.msg.KbNodeConnectionType;
import com.caipos.actor.common.data.rule.RuleNodeState;
import com.caipos.actor.common.data.rule.RuleNode;
import com.caipos.actor.common.msg.KbMsg;
import com.caipos.actor.common.msg.KbMsgMetaData;
import com.caipos.actor.api.KbContext;
import com.caipos.service.RuleChainService;
import com.caipos.service.TenantService;
import com.caipos.util.ListeningExecutor;
import io.netty.channel.EventLoopGroup;
import lombok.extern.slf4j.Slf4j;

import javax.management.relation.RelationService;
import javax.script.ScriptEngine;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;


@Slf4j
public class DefaultKbContext implements KbContext {

    private final ActorSystemContext mainCtx;
    private final String ruleChainName;
    private final RuleNodeCtx nodeCtx;

    public DefaultKbContext(ActorSystemContext mainCtx, String ruleChainName, RuleNodeCtx nodeCtx) {
        this.mainCtx = mainCtx;
        this.ruleChainName = ruleChainName;
        this.nodeCtx = nodeCtx;
    }

    @Override
    public void tellSuccess(KbMsg msg) {
        tellNext(msg, Collections.singleton(KbNodeConnectionType.SUCCESS));
    }

    @Override
    public void tellNext(KbMsg msg, String relationType) {
        tellNext(msg, Collections.singleton(relationType));
    }

    @Override
    public void tellNext(KbMsg msg, Set<String> relationTypes) {

    }

    @Override
    public void tellSelf(KbMsg msg, long delayMs) {

    }

    @Override
    public void tellFailure(KbMsg msg, Throwable th) {

    }

    @Override
    public void enqueue(KbMsg msg, Runnable onSuccess, Consumer<Throwable> onFailure) {

    }

    @Override
    public void input(KbMsg msg, RuleChainId ruleChainId) {

    }

    @Override
    public void output(KbMsg msg, String relationType) {

    }

    @Override
    public void enqueue(KbMsg msg, String queueName, Runnable onSuccess, Consumer<Throwable> onFailure) {

    }

    @Override
    public void enqueueForTellFailure(KbMsg msg, String failureMessage) {

    }

    @Override
    public void enqueueForTellFailure(KbMsg kbMsg, Throwable t) {

    }

    @Override
    public void enqueueForTellNext(KbMsg msg, String relationType) {

    }

    @Override
    public void enqueueForTellNext(KbMsg msg, Set<String> relationTypes) {

    }

    @Override
    public void enqueueForTellNext(KbMsg msg, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure) {

    }

    @Override
    public void enqueueForTellNext(KbMsg msg, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure) {

    }

    @Override
    public void enqueueForTellNext(KbMsg msg, String queueName, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure) {

    }

    @Override
    public void enqueueForTellNext(KbMsg msg, String queueName, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure) {

    }

    @Override
    public void ack(KbMsg kbMsg) {

    }

    @Override
    public KbMsg newMsg(String queueName, KbMsgType type, EntityId originator, KbMsgMetaData metaData, String data) {
        return null;
    }

    @Override
    public KbMsg transformMsg(KbMsg origMsg, KbMsgType type, EntityId originator, KbMsgMetaData metaData, String data) {
        return null;
    }

    @Override
    public KbMsg transformMsg(KbMsg origMsg, KbMsgMetaData metaData, String data) {
        return null;
    }

    @Override
    public KbMsg transformMsgOriginator(KbMsg origMsg, EntityId originator) {
        return null;
    }

    @Override
    public KbMsg attributesDeletedActionMsg(EntityId originator, RuleNodeId ruleNodeId, String scope, List<String> keys) {
        return null;
    }

    @Override
    public void schedule(Runnable runnable, long delay, TimeUnit timeUnit) {

    }

    @Override
    public boolean isLocalEntity(EntityId entityId) {
        return false;
    }

    @Override
    public RuleNodeId getSelfId() {
        return null;
    }

    @Override
    public RuleNode getSelf() {
        return null;
    }

    @Override
    public String getRuleChainName() {
        return "";
    }

    @Override
    public String getQueueName() {
        return "";
    }

    @Override
    public TenantId getTenantId() {
        return null;
    }

    @Override
    public TenantService getTenantService() {
        return null;
    }

    @Override
    public String getDeviceStateNodeRateLimitConfig() {
        return "";
    }

    @Override
    public RuleChainService getRuleChainService() {
        return null;
    }

    @Override
    public RelationService getRelationService() {
        return null;
    }

    @Override
    public boolean isExternalNodeForceAck() {
        return false;
    }

    @Override
    public ScriptEngine createJsScriptEngine(String script, String... argNames) {
        return null;
    }

    @Override
    public void logJsEvalRequest() {

    }

    @Override
    public void logJsEvalResponse() {

    }

    @Override
    public void logJsEvalFailure() {

    }

    @Override
    public String getServiceId() {
        return "";
    }

    @Override
    public EventLoopGroup getSharedEventLoop() {
        return null;
    }

    @Override
    public RuleNodeState findRuleNodeStateForEntity(EntityId entityId) {
        return null;
    }

    @Override
    public void removeRuleNodeStateForEntity(EntityId entityId) {

    }

    @Override
    public RuleNodeState saveRuleNodeState(RuleNodeState state) {
        return null;
    }

    @Override
    public void clearRuleNodeStates() {

    }

    @Override
    public void removeListeners() {

    }

    @Override
    public ListeningExecutor getExternalCallExecutor() {
        return mainCtx.getExternalCallExecutorService();
    }

}
